// 登录状态管理
const LOGIN_STATE_KEY = 'login_state';

// 获取登录状态
export const getLoginState = () => {
  return uni.getStorageSync(LOGIN_STATE_KEY) || false;
};

// 设置登录状态
export const setLoginState = (state) => {
  uni.setStorageSync(LOGIN_STATE_KEY, state);
};

// 移除登录状态
export const removeLoginState = () => {
  uni.removeStorageSync(LOGIN_STATE_KEY);
};

// 等待登录完成
export const waitForLogin = () => {
  return new Promise((resolve) => {
    const checkLoginState = () => {
      if (getLoginState()) {
        resolve();
      } else {
        setTimeout(checkLoginState, 100);
      }
    };
    checkLoginState();
  });
};